/*
 * Copyright (C) 2019 Baidu, Inc. All Rights Reserved.
 */
package com.bootdo.hjh.service.impl;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bootdo.hjh.cache.NodeInfo;
import com.bootdo.hjh.dao.StockDao;
import com.bootdo.hjh.domain.CashPointsDO;
import com.bootdo.hjh.domain.CashPointsDOExample;
import com.bootdo.hjh.domain.StockDO;
import com.bootdo.hjh.service.StockService;

@Service
public class StockServiceImpl implements StockService {
	@Autowired
	private StockDao stockDao;

	@Override
	public StockDO get(Integer id){
		return stockDao.get(id);
	}

	@Override
	public List<StockDO> list(Map<String, Object> map){
		return stockDao.list(map);
	}

	@Override
	public int count(Map<String, Object> map){
		return stockDao.count(map);
	}

	@Override
	public int save(StockDO stock){
		return stockDao.save(stock);
	}

	@Override
	public int update(StockDO stock){
		return stockDao.update(stock);
	}

	@Override
	public int remove(Integer id){
		return stockDao.remove(id);
	}

	@Override
	public int batchRemove(Integer[] ids){
		return stockDao.batchRemove(ids);
	}

	@Override
	public Integer myStockBalance(Long userId, Integer productType) {
		Integer stockBalance = stockDao.myStockBalance(userId, productType);
		if (stockBalance == null) {
			stockBalance = 0;
		}
		return stockBalance;
	}

	@Override
	public List<StockDO> listStocks(Long userId, Integer type, Date beginDate, Date endDate, Integer offset,
											 Integer limit) {
		List<StockDO> stockDOS = stockDao.listStocks(userId, type, beginDate, endDate, offset, limit);

		if (stockDOS == null) {
			stockDOS = new ArrayList<>();
		}

		return stockDOS;

	}

	public Integer countStocks(Long userId, Integer type, Date beginDate, Date endDate) {
		Integer cnt = stockDao.countStocks(userId, type, beginDate, endDate);

		if (cnt == null) {
			cnt = 0;
		}
		return cnt;
	}

	@Override
	public int sumStocks(Long userId, Integer type, Date beginDate, Date endDate) {
		Integer sum = stockDao.sumStocks(userId, type, beginDate, endDate);

		if (sum == null) {
			sum = 0;
		}

		return sum;
	}
}
